<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date'}){}%>
</head>
<body>
<div class="wrapper wrapper-content">
	<input type="hidden" id="createStatus" value="${createStatus}">
	<div class="row">
		<div class="col-sm-12">
			<!-- START 数据表格 -->
			<table id="stockTable"
				   data-toolbar="#toolbar"
				   data-side-pagination="server"
				   data-pagination="true"
				   data-resizable="true"
				   data-side-pagination="server"
				   data-url="/sea/physical/stockCreate/findByCnd.do?createStatus=${createStatus}"
				   data-page-size="15">
			</table>
			<!-- END 数据表格 -->

			<!-- END 右侧数据 -->
		</div>
	</div>
</div>
<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
	<!-- START 内容部分 -->
	<div class="container" >
		<form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
			<div class="form-group" style="margin-top: 20px">
				<label class="control-label col-sm-2" style="max-width: 100px">日期</label>
				<div class="col-sm-6" style="max-width: 300px">
					<input type="text" id="createOperateTime" name="createOperateTime" value="" class="form-control">
				</div>
			</div>
			<div class="form-group" style="margin-top: 20px">
				<label class="control-label col-sm-2" style="max-width: 100px">备注</label>
				<div class="col-sm-6" style="max-width: 300px">
					<input type="text" id="createReason" name="createReason" value="" class="form-control">
				</div>
				<input id="id" name="id" hidden="hidden">
			</div>
			<div class="form-group" style="margin-top: 20px">
				<label class="control-label col-sm-7" style="max-width: 100px"></label>
				<button type="button" class="save-btn btn btn-primary">
					<i class="fa fa-save"></i> 保存
				</button>
			</div>
		</form>
	</div>
	<!-- END 内容部分 -->
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,bootstrap-table-zh-CN,layer,laydate,layui'}){}%>
<script>
    var $stockTable = $('#stockTable'),selections=[];
	laydate.render({
		elem: '#createOperateTime',
		type: 'date',
		trigger: 'click', //修改触发方式
		format: 'yyyy-MM-dd'
	});
    $(function(){
        //START 表格配置
        $stockTable.bootstrapTable({
			detailView: true,
            columns: [
                {
                    title: '柜号',
                    field: 'createNo',
                    align: 'center',
                    valign: 'middle'
                },
				{
					title: '装柜仓库',
					field: 'createWareName',
					align: 'center',
					valign: 'middle'
				},
                {
                    title: '目的仓库',
                    field: 'createDestWareName',
                    align: 'center',
                    valign: 'middle'
                },
				{
					title: '币种',
					field: 'createMoneyType',
					align: 'center',
					valign: 'middle'
				},
				{
					title: '运费',
					field: 'createMoney',
					align: 'center',
					valign: 'middle'
				},
				{
					title: '托盘数',
					field: 'createPallet',
					align: 'center',
					valign: 'middle'
				},{
					title: '总件数',
					field: 'createNumber',
					align: 'center',
					valign: 'middle'
				},{
					title: '总箱数',
					field: 'createBoxNumber',
					align: 'center',
					valign: 'middle'
				},{
					title: '总体积',
					field: 'createVolume',
					align: 'center',
					valign: 'middle'
				},{
					title: '状态',
					field: 'createStatus',
					align: 'center',
					valign: 'middle',
					formatter:function (v,r) {
						var result='';
						switch (v) {
							case 1:
								result='待发运';
								break;
							case 2:
								result='已发运';
								break;
							case 3:
								result='已送货';
								break;
							case 4:
								result='已入库';
								break;
							default:
								result='';
						}
						return result;
					}
				},{
					title: '发运时间',
					field: 'sendTime',
					align: 'center',
					valign: 'middle'
				},{
					title: '送货时间',
					field: 'createOperateTime',
					align: 'center',
					valign: 'middle'
				},{
					title: '操作',
					field: 'operate',
					align: 'center',
					valign: 'middle',
					formatter: optFormatter
				}
            ],
            onLoadSuccess : function() {
				var createStatus=$("#createStatus").val();
				if(createStatus=='2'){
					// $('#stockTable').bootstrapTable('hideColumn', 'driveBoatDate');
					$('#stockTable').bootstrapTable('hideColumn', 'createOperateTime');
				}
				if(createStatus=='3'){
					$('#stockTable').bootstrapTable('hideColumn', 'sendTime');
					// $('#stockTable').bootstrapTable('hideColumn', 'createOperateTime');
				}
				//新增
				$('.edit-btn').on('click',function(){//新增
					var id = $(this).attr('data-val');
					layer.open({
						title: false,
						closeBtn: 0,
						type: 2,
						area: ['100%','100%'],
						skin: 'layer-ext-espresso',
						content: ['/sea/physical/stockCreate/editpage.do?id='+id, 'yes']
					});
				});
				$('.deliver-btn').on('click',function () {
					// var id = $(this).attr('data-val');
					// //发运计划
					// layer.confirm('一经送货,无法取消,确定要送货？', {
					// 	btn: ['确定','取消'],title:'提示'
					// }, function(){
					// 	send(id,3);
					// });
					var id = $(this).attr('data-val');
					$('#id').val(id);
					layer.open({
						type:1,
						title:'确认日期',
						area:['600px','250px'],
						skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
						shadeClose:false,
						resize: false,
						scrollbar: false,
						maxmin: false,//出现最大化按钮
						content:$('#layer_window')
					})
				});
				$('.stock-btn').on('click',function () {
					var id = $(this).attr('data-val');
					$('#id').val(id);
					layer.open({
						type:1,
						title:'确认日期',
						area:['600px','250px'],
						skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
						shadeClose:false,
						resize: false,
						scrollbar: false,
						maxmin: false,//出现最大化按钮
						content:$('#layer_window')
					})
				});
				$('.detail-btn').on('click',function(){
					var id = $(this).attr('data-val');
					layer.open({
						type: 2,
						area: ['700px','500px'],
						content: ['/sea/physical/stockCreate/record.do?id='+id, 'yes']
					});
				});
            },
			onExpandRow: function (index, row, $detail) {
				InitSubTable(index, row, $detail);
			}
        });
        //END 表格配置

        //表格高度自适应
        $(window).resize(function () {
            $stockTable.bootstrapTable('resetView', {
                height: getHeight()
            });
        });
    });

	var cur_table;
	//初始化子表格(无线循环)
	function InitSubTable (index, row, $detail) {
		var parentId = row.id;
		cur_table = $detail.html('<table></table>').find('table');
		$(cur_table).bootstrapTable({
			url: '/sea/physical/stockCreate/findByCreateId',
			method: 'get',
			clickToSelect: true,
			queryParams: {createId: parentId},
			ajaxOptions: {createId: parentId},
			clickToSelect: true,
			uniqueId: "id",
			pageSize: 10,
			pageList: [10, 25],
			columns: [
				{
					field: 'createNo',
					title: '柜号'
				}, {
					field: 'createShipmentId',
					title: 'shipmentId'
				},{
					field: 'createSku',
					title: 'sku'
				},{
					field: 'productName',
					title: '商品名称'

				},{
					field: 'productColorName',
					title: '颜色'

				},{
					field: 'productCm',
					title: '尺码(CM)'

				},{
					field: 'productInch',
					title: '尺码(INCH)'

				},{
					field: 'createNumber',
					title: '数量'

				},{
					field: 'createPackage',
					title: '装箱量'

				},{
					field: 'createBoxNumber',
					title: '箱数'

				},{
					field: 'createVolume',
					title: '总体积'
				}],
			onLoadSuccess: function () {

			}
		});
	};


	function optFormatter(value,row) {
		var content = '';
		if(row.createStatus==2){
			content += '&nbsp;<button class="deliver-btn btn btn-xs btn-info" data-val="' + row.id + '" title="送货"><i class="fa fa-truck"></i>  送货</button>';
		}
		if(row.createStatus==3){
			content += '&nbsp;<button class="stock-btn btn btn-xs btn-info" data-val="' + row.id + '" title="入库"><i class="fa fa-truck"></i>  入库</button>';
		}
		content += '&nbsp;<button class="detail-btn btn btn-xs btn-default" data-val="' + row.id + '" title="查看记录"><i class="fa fa-github-alt"></i> 查看记录</button>';
		return content;
	}

	$('.save-btn').on('click',function () {
		send();
	});

	function send() {
		layer.closeAll(); //关闭弹窗
		layer.load();
		var createReason=$("#createReason").val();
		var createOperateTime=$("#createOperateTime").val();
		var createStatus=parseInt($("#createStatus").val());
		var id=$("#id").val();
		$.post('/sea/physical/stockCreate/updateStatus.do',{id:id,createStatus:createStatus+1,createId:id,createReason:createReason.toString(),createOperateTime:createOperateTime.toString()},function(data){
			if( data.ok ){
				parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
					$stockTable.bootstrapTable('refresh');
					layer.closeAll(); //关闭弹窗
				});
			}else{
				layer.closeAll(); //关闭弹窗
				layer.msg(data.msg,{icon: 0,time:5000,shade: [0.8, '#393D49']});
			}
		});
	}
</script>
</body>
</html>
